import com.github.pagehelper.PageHelper;
import com.qf.dao.UserDao;
import com.qf.pojo.User;
import com.qf.util.MyBatisUtils;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/*
 *@Description:
 *@author:刘哥
 *@Date:19:40 2022/7/7
 */
public class Demo {
    @Test
    public void test01(){
        try {
            UserDao userDao = MyBatisUtils.getMapper(UserDao.class);
            System.out.println( userDao.selectById(3));
            MyBatisUtils.commit();
        } catch (Exception e) {
            e.printStackTrace();
            MyBatisUtils.rollback();
        }
    }
    @Test
    public void test02(){
        try {
            UserDao userDao = MyBatisUtils.getMapper(UserDao.class);
            PageHelper.startPage(1,2);
            System.out.println( userDao.select());
            MyBatisUtils.commit();
        } catch (Exception e) {
            e.printStackTrace();
            MyBatisUtils.rollback();
        }
    }
    @Test
    public void test03(){
        try {
            UserDao userDao = MyBatisUtils.getMapper(UserDao.class);
            PageHelper.startPage(1,2);
            User user=new User();
            user.setName("liu");
            user.setSex("男");
            user.setId(4);
            userDao.update(user);
            MyBatisUtils.commit();
        } catch (Exception e) {
            e.printStackTrace();
            MyBatisUtils.rollback();
        }
    }
    @Test
    public void test04(){
        try {
            UserDao userDao = MyBatisUtils.getMapper(UserDao.class);
            List<Integer> ids=new ArrayList<Integer>();
            ids.add(4);
            userDao.delete(ids);
            MyBatisUtils.commit();
        } catch (Exception e) {
            e.printStackTrace();
            MyBatisUtils.rollback();
        }
    }

}
